﻿<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <link href="Content/css/framework-font.css" rel="stylesheet" />
    <link href="Content/css/framework-theme.css" rel="stylesheet" />
    <script src="Content/js/jquery/jquery-2.1.1.min.js"></script>
    <link href="Content/js/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <script src="Content/js/bootstrap/bootstrap.js"></script>
    <link href="Content/js/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <script src="Content/js/bootstrap-table/bootstrap-table.js"></script>
    <script src="Content/js/bootstrap-table/bootstrap-treegrid.js"></script>
    <script src="Content/js/bootstrap-table/bootstrap-table-zh-CN.js"></script>
    <link href="Content/css/framework-ui.css" rel="stylesheet" />
    <script src="Content/js/framework-ui.js"></script>
    <link href="Content/js/select2/select2.min.css" rel="stylesheet" />
    <script src="Content/js/select2/select2.min.js"></script>
    <link href="Content/js/wizard/wizard.css" rel="stylesheet" />
    <script src="Content/js/wizard/wizard.js"></script>
    <script src="Content/js/validate/jquery.validate.min.js"></script>
    <script src="Content/layer-v3.1.0/layer/layer.js"></script>
    <script src="Content/js/base.js"></script>

    <script type="text/javascript">

        $(function () {

            initTable();

            bindCommpany();

            $("#btnsaveuser").click(function () {

                if ($("#addMark").val() == "add") {
                    addJob();
                }
                else {

                    editJob();
                }
            });

            $('#user-modal-table').on('hide.bs.modal', function () {

                $("#jobId").val("");
                $("#addMark").val("");
                $("#jobName").val("");
                $("#enCode").val("");
            });
        });

        function initTable() {

            var pagedata = JSON.stringify({

                "params": {
                    "id": 1
                },

                "row": 10,
                "pageNo": 1
            });

            //先销毁表格
            $("#gridList").bootstrapTable('destroy');
            $("#gridList").bootstrapTable({
                url: baseUrl() + "jobInfo/queryPage",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                striped: true,//表格显示条纹
                pagination: true,//是否显示分页
                showColumns: false,
                search: false, //搜索框
                singleSelect: false,
                searchOnEnterKey: true, //按回车触发搜索功能
                searchAlign: "left", //搜索框的位置
                buttonsAlign: "left", //按钮的位置
                showRefresh: false,//是否显示刷新按钮
                sidePagination: "server",//表示从服务端获取数据 --必须有
                queryParamsType: "undefined",//定义参数类型
                sortable: false, //是否启用排序
                sortOrder: "asc", //排序方式
                clickToSelect: true,
                uniqueId: "id", //每一行的唯一表示，一般为主键
                queryParams: function (params) {

                    return pagedata;
                },
                onClickRow: function (row, $element) {
                    $('.info').removeClass('info');
                    $($element).addClass('info');
                },
                columns: [
                {
                    field: 'id',
                    title: '序号',
                    align: 'center',
                },
                {
                    field: 'jobName',
                    title: '职位名称',
                    align: 'center',
                },
                {
                    field: 'enCode',
                    title: '职位代码',
                    align: 'center',
                },
                {
                    field: 'orgInfo.fullName',
                    title: '所属机构',
                    align: 'center',
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                }
                ,
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    events: "operateEvents",
                    formatter: operateFormatter
                }
                ],
                onLoadSuccess: function (data) {
                    console.log(data);
                },
            })
        };
        function operateFormatter(value, row, index) {
            return [
            "<button type='button'  onclick=\"removeJob('" + row.id + "')\" class='RoleOfA btn btn-default  btn-sm' style='margin-right:5px;'>删除</button>",
             "<button type='button'  onclick=\"showModal('" + row.id + "')\" class='RoleOfA btn btn-default  btn-sm' style='margin-right:5px;'>修改</button>",
            ].join('');
        }

        function bindCommpany() {

            var nulldata = "{}";
            $.ajax({
                url: baseUrl() + "orgInfo/queryList",
                type: "post",
                data: nulldata,
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (res) {

                    if (res.success == true) {
                        var _html = "";

                        $.each(res.data.rows, function (i, j) {
                            if (j.orgType != 3) {

                                _html += "<option value='" + j.id + "'>" + j.fullName + "</option>";
                            }
                        })
                        $("#orgId").append(_html);
                    }
                }
            });
        };

        function showModal(type) {

            if (type == "add") {

                $("#ddTitle").html("新增岗位");
                $("#addMark").val("add");
            }
            else {

                $("#ddTitle").html("编辑岗位");
                $.ajax({
                    url: baseUrl() + "jobInfo/queryById",
                    data: type,
                    type: "post",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        if (data.success == true) {

                            $("#jobId").val(type);
                            $("#jobName").val(data.data.jobName);
                            $("#enCode").val(data.data.enCode);
                            $("#orgId").val(data.data.orgInfo.id);
                        }
                        else {
                            layer.msg("添加失败");
                        }
                    }
                });
            }
            $("#user-modal-table").modal({ backdrop: 'static', keyboard: false });
        };

        function addJob() {
            debugger;
            var data = JSON.stringify({

                "orgId": $("#orgId").val(),
                "jobName": $("#jobName").val(),
                "enCode": $("#enCode").val()
            });

            $.ajax({
                url: baseUrl() + "jobInfo/insert",
                data: data,
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data.success == true) {
                        $('#user-modal-table').modal('hide');
                        layer.msg(data.msg);
                        $("#refresh").trigger('click');
                    }
                    else {

                        layer.msg("添加失败");
                    }
                }
            });
        };

        function editJob() {

            var data = JSON.stringify({

                "id": $("#jobId").val(),
                "orgId": $("#orgId").val(),
                "jobName": $("#jobName").val(),
                "enCode": $("#enCode").val()
            });
            $.ajax({
                url: baseUrl() + "jobInfo/update",
                data: data,
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data.success == true) {
                        $('#user-modal-table').modal('hide');
                        layer.msg(data.msg);
                        $("#refresh").trigger('click');
                    }
                    else {

                        layer.msg("编辑失败");
                    }
                    console.log(data);
                }
            });

        };

        function removeJob(id) {

            layer.confirm('确定删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                var data = "[" + id + "]";
                $.ajax({
                    url: baseUrl() + "jobInfo/delete",
                    data: data,
                    type: "post",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        if (data.success == true) {
                            $('#user-modal-table').modal('hide');
                            layer.msg(data.msg);
                            $("#refresh").trigger('click');
                        }
                        else {

                            layer.msg("删除失败");
                        }
                    }
                });

            }, function () {
                layer.msg('好的');
            });
        };

    </script>
</head>
<body>

    <input type="hidden" id="addMark" />
    <input type="hidden" id="jobId" />

    <div class="btn-group">
        <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="showModal('add')"><i class="fa fa-plus"></i>添加岗位</a>
    </div>
    <div class="btn-group">
        &nbsp; &nbsp; &nbsp;
        <a id="refresh" class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
    </div>
    <div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
        <div class="ui-layout-west">
            <div id="itemTree"></div>
        </div>
        <div class="ui-layout-center">
            <div class="gridPanel">
                <table id="gridList"></table>
            </div>
        </div>
    </div>
</body>
</html>

<div id="user-modal-table" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <span id="ddTitle"></span>
                </div>
            </div>
            <div class="modal-body no-padding" style="margin-top: 10px">

                <div style="padding-top: 20px; margin-right: 30px;">
                    <table class="form">
                        <tr>
                            <th class="formTitle">职位名称</th>
                            <td class="formValue">
                                <input id="jobName" name="jobName" type="text" class="form-control required" placeholder="职位名称" />
                            </td>
                            <th class="formTitle">职位编号</th>
                            <td class="formValue">
                                <input id="enCode" name="enCode" type="text" class="form-control required" placeholder="请输入职位编号" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle" valign="top" style="padding-top: 5px;">
                                所属机构
                            </th>
                            <td class="formValue" colspan="3">
                                <select id="orgId" name="orgId" class="form-control required"></select>
                            </td>
                        </tr>
                    </table>
                </div>

            </div>
            <div class="modal-footer no-margin-top">
                <button class="btn btn-sm btn-default" data-dismiss="modal">
                    <i class="icon-remove"></i>关闭
                </button>
                <button class="btn btn-sm btn-info pull-right" id="btnsaveuser">
                    <i class="icon-save"></i>保存
                </button>
            </div>
        </div>
    </div>
</div>
